﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Company.Core.Helpers
{
    public class CurveHelper
    {
        /// <summary>
        /// 当前房间保存csv的文件名
        /// </summary>
        /// <param name="roomId"></param>
        /// <param name="startTime"></param>
        /// <param name="endTime"></param>
        public static string GetCurveFullName(int roomId, DateTime startTime, DateTime endTime)
        {
            // Room_1_20231010120000_20231010123000.csv
            string roomName = $"Room_{roomId}";
            string fileName = $"{roomName}_{startTime:yyyyMMddHHmmss}_{endTime:yyyyMMddHHmmss}.csv";
            string folder = $"{Environment.CurrentDirectory}\\History\\{startTime.Year}";
            string fullName = $"{folder}\\{fileName}";// Environment.CurrentDirectory 当前程序运行目录
            if (!System.IO.Directory.Exists(folder))
            {
                System.IO.Directory.CreateDirectory(folder);
            }
            return fullName;
        }

        /// <summary>
        /// 获取上一次文件名的路径
        /// </summary>
        /// <param name="roomId"></param>
        /// <param name="startTime"></param>
        /// <param name="filename"></param>
        /// <returns></returns>
        public static string GetLastCurveFullName(int roomId, DateTime startTime, string? filename)
        {
            // Room_1_20231010120000_20231010123000.csv
            string roomName = $"Room_{roomId}";
            string fileName = $"{roomName}_{filename}.csv";
            string folder = $"{Environment.CurrentDirectory}\\History\\{startTime.Year}";
            string fullName = $"{folder}\\{fileName}";// Environment.CurrentDirectory 当前程序运行目录
            if (!System.IO.Directory.Exists(folder))
            {
                System.IO.Directory.CreateDirectory(folder);
            }
            return fullName;
        }
        /// <summary>
        /// 获取当前房间历史数据文件所在的文件夹
        /// </summary>
        /// <param name="year"></param>
        /// <returns></returns>
        public static string GetCurveFolder(int year)
        {
            string folder = $"{Environment.CurrentDirectory}\\History\\{year}";
            if (!System.IO.Directory.Exists(folder))
            {
                System.IO.Directory.CreateDirectory(folder);
            }
            return folder;
        }
    }
}
